package com.bluestone.context;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.bluestone.scripts.ActionScript;
import com.bluestone.scripts.Command;

public class CommandContext extends ContextBase {
	public CommandContext(Command cmd){
		this.command = cmd;
		this.setId(command.getId());
		this.createActionContext();
	}
	
	private Command command = null;
	
	private void createActionContext(){
		List actions = command.getActions();
		for(int i=0; i< actions.size(); i++){
			ActionScript action = (ActionScript) actions.get(i);
			action.setName(""+i);
			ActionContext context = new ActionContext(action);
			actioncontexts.add(context);
			
		}
	}
	private ArrayList<ActionContext> actioncontexts = new ArrayList<ActionContext>();
    public ActionContext getActionContext(ActionScript action){
    	ActionContext context = null;
    	for(int i=0; i<actioncontexts.size(); i++){
    		ActionContext temp = actioncontexts.get(i);
    		if(action.getName().equalsIgnoreCase(temp.getId())){
    			context = temp;
    			break;
    		}
    		
    	}
    	return context;
    }
	public Command getCommand() {
		return command;
	}
	public void setCommand(Command command) {
		this.command = command;
	}

}
